﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HaiFang;

namespace HaiFang
{
    public partial class Index : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!Page.User.Identity.IsAuthenticated)
                {
                    CustomAuthentication.RedirectToLoginPage();
                }
            }
        }

        protected void btnLogout_Click(object sender, EventArgs e)
        {
            CustomAuthentication.SignOut();
            CustomAuthentication.RedirectToLoginPage();
        }

        public static string UserName
        {
            get
            {
                string username = string.Empty;
                SimpleUserInfo userinfo = WebHelper.GetCurrentUserInfo();
                if (userinfo != null)
                {
                    username = userinfo.UserName;
                }
                return username;
            }
        }

        public static string ProjectName
        {
            get
            {
                string projectname = string.Empty;
                int userid=WebHelper.GetCurrentUserID();
                int projectid=WebHelper.GetCurrentUserProjectID();
                if (userid > 0 && projectid > 0)
                {
                    IList<ProjectInfoBase> pis = ProxyProjectInfo.QueryProjectInfoSingle(userid, projectid);
                    if (pis != null && pis.Count > 0)
                    {
                        projectname = pis[0].ProjectName;
                    }
                }
                return projectname;
            }
        }
    }
}
